package leetcode.editor.vscdev.hot100;

public class lc415_addStrings {
    
}

class Solution {
    public String addStrings(String num1, String num2) {
        StringBuilder res = new StringBuilder();
        int i = num1.length() - 1, j = num2.length() - 1, carry = 0;
        while (i >= 0 || j >= 0) {
            int m = i>=0 ? num1.charAt(i) - '0' : 0;
            int n = j>=0 ? num2.charAt(j) - '0' : 0;
            int sum = m + n + carry;
            carry = sum/10;
            res.append(sum%10);
            i--;j--;
        }
        if (carry == 1) {
            res.append(1);
        }
        return res.reverse().toString();
    }
}